package com.ruoyi.wvp.controller;

import java.util.List;
import java.util.Date;

import com.ruoyi.wvp.service.ICommunityEventCountService;
import com.ruoyi.wvp.service.impl.CommunityEventCountServiceImpl;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wvp.domain.DutyCount;
import com.ruoyi.wvp.service.IDutyCountService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.enums.DeletedEnum;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

/**
 * 督导员统计Controller
 * 
 * @author ruoyi
 * @date 2024-10-23
 */
@RestController
@RequestMapping("/wvp/count")
@Tag(name = "【督导员统计】管理")
public class DutyCountController extends BaseController{
    @Autowired
    private IDutyCountService dutyCountService;

    /**
     * 查询督导员统计列表
     */
    @Operation(summary = "查询督导员统计列表")
    @PreAuthorize("@ss.hasPermi('wvp:count:list')")
    @GetMapping("/list")
    public TableDataInfo list(DutyCount dutyCount) {
        Page<DutyCount> page = getPage();
        dutyCountService.pageList(page, dutyCount);
        return getTableDataInfo(page);
    }


    /**
     * 导出督导员统计列表
     */
    @Operation(summary = "导出督导员统计列表")
    @PreAuthorize("@ss.hasPermi('wvp:count:export')")
    @Log(title = "督导员统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void exportAll(HttpServletResponse response,DutyCount dutyCount){
        List<DutyCount> list = dutyCountService.listAll(dutyCount);
        ExcelUtil<DutyCount> util = new ExcelUtil<DutyCount>(DutyCount.class);
        util.exportExcel(response, list, "设备数据");
    }

    /**
     * 获取督导员统计详细信息
     */
    @Operation(summary = "获取督导员统计详细信息")
    @PreAuthorize("@ss.hasPermi('wvp:count:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id){
        return success(dutyCountService.getById(id));
    }

    /**
     * 新增督导员统计
     */
    @Operation(summary = "新增督导员统计")
    @PreAuthorize("@ss.hasPermi('wvp:count:add')")
    @Log(title = "督导员统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DutyCount dutyCount){

        return toAjax(dutyCountService.save(dutyCount));
    }

    /**
     * 修改督导员统计
     */
    @Operation(summary = "修改督导员统计")
    @PreAuthorize("@ss.hasPermi('wvp:count:edit')")
    @Log(title = "督导员统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DutyCount dutyCount){

        return toAjax(dutyCountService.updateById(dutyCount));
    }

    /**
     * 删除督导员统计
     */
    @Operation(summary = "删除督导员统计")
    @PreAuthorize("@ss.hasPermi('wvp:count:remove')")
    @Log(title = "督导员统计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable( name = "ids" ) Long[] ids) {
        QueryWrapper<DutyCount> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("id",List.of(ids));
        DutyCount dutyCount = new DutyCount();
        return toAjax(dutyCountService.update(dutyCount,queryWrapper));
    }


    @PostMapping("/queryByDate")
    public AjaxResult queryByDate(@RequestBody DutyCount dutyCount){

        return AjaxResult.success(dutyCountService.countStatistics(dutyCount));
    }

}
